import { config } from 'lin-mizar';
import { Sequelize, Model } from 'sequelize';
import sequelize from '../lib/db';

class Music extends Model {
}

Music.init(
  {
    id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    title: {
      type: Sequelize.STRING(50),
      allowNull: false
    },
    pubdate: {
      type: Sequelize.DATE,
      allowNull: true,
    },
    content: {
      type: Sequelize.STRING(500),
      allowNull: true
    },
    type: {
      type: Sequelize.INTEGER,
    },
    fav_nums: {
      type: Sequelize.INTEGER,
      defaultValue: 0
    },
    image: {
      type: Sequelize.STRING(100),
      get(){
        const image = this.getDataValue('image')
        return config.getItem('localMainImgUrlPrefix') + image
      }
    },
    status: {
      type: Sequelize.INTEGER,
    }
  },
  {
    tableName: 'music',
    modelName: 'music',
    paranoid: true,
    timestamps: true,
    underscored: true,
    createdAt: 'create_time',
    updatedAt: 'update_time',
    deletedAt: 'delete_time',
    sequelize,
  }
);

export { Music };
